package per.dj.testpro.netty;


import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component
@Qualifier("springProtocolInitializer")
@Data
public class StringProtocolInitalizer extends ChannelInitializer<SocketChannel> {

    @Autowired
    ProtocolDecoder protocolDecoder;

    @Autowired
    ProtocolEncoder protocolEncoder;

    @Autowired
    ServerHandler serverHandler;

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast("decoder", new ProtocolDecoder());
        pipeline.addLast("handler", serverHandler);
        pipeline.addLast("encoder", new ProtocolEncoder());
    }


}
